import { chunkArray, randomUid } from '../utils';
import { getRandomForArr, now, randomInt, names } from './util';

export const users = names.map((name) => {
  return {
    name,
    phone: '138****8888',
    pic: `https://picsum.photos/360?v=${randomUid()}`,
    online: getRandomForArr(['0', '1']),
    time: now,
    counts: randomInt(),
    level: randomInt(5, 1),
    switch: getRandomForArr([true, false]),
    status: getRandomForArr(['success', 'warning', 'danger']),
    progress: randomInt(100, 1),
    tags: Array.from({ length: randomInt(10, 1) }).map((_) =>
      getRandomForArr(['success', 'primary', 'warning', 'danger'])
    )
  };
});

export const getDatas = (params?): Promise<any> => {
  return new Promise<any>((resolve) => {
    setTimeout(() => {
      let result = params ? chunkArray(users, params.pageSize) : [users];
      resolve({
        data: result[(params?.pages ?? 1) - 1],
        total: users.length
      });
    }, 1000);
  });
};
